package com.ruoyi.cmdb.util;

import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Value;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;

//定义保存私钥到文件的工具类
public class SavePrivateKeyToFile {
    @SneakyThrows
    public static Path save(String privateKeyString,Integer randomLength){
        String randomString= RandomStringGenerator.generateRandomString(randomLength);
        String privateKeyPath = "private_key_file."+randomString;
        File file = new File(privateKeyPath);
        Path privateKeyAbsolutePathObject = Paths.get(String.valueOf(file));
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            writer.write(privateKeyString);
            //Path absolutePath = privateKeyAbsolutePathObject.toAbsolutePath();
            //System.out.println("文件的绝对路径是: " + absolutePath);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return privateKeyAbsolutePathObject;
    }
}
